package com.fzrskj.cloud.free.user.utils.agent;

import com.fzrskj.cloud.free.core.enums.DicParamEnum;
import com.fzrskj.cloud.free.dic.bean.DicParam;
import com.fzrskj.cloud.free.dic.bean.DicVipgrade;
import com.fzrskj.cloud.free.dic.utils.DicParamUtils;
import com.fzrskj.cloud.free.dic.utils.DicVipgradeUtils;
import org.apache.commons.collections.map.HashedMap;

import java.util.List;
import java.util.Map;

/**
 * InitDataOfUserLevelHelper.
 *
 * @author zj.
 *         Created on 2019/9/2 0002.
 */
public class InitDataOfUserLevelHelper {
    final static String levelCode = "v1";
    final static String levelName = "大众会员";
    final static Integer maxCharge = 1000;
    final static Integer minCharge = 0;
    final static Integer rebate = 10;
    public static void initUserLevel(Integer agentId) {
        DicVipgradeUtils vipgradeUtils = new DicVipgradeUtils();
        Map<String, Object> where = new HashedMap();
        where.put("agentId", agentId);
        List<DicVipgrade> vipgrades = vipgradeUtils.queryDicVipgradeListFree(where, 1, 1);
        if (null == vipgrades || vipgrades.isEmpty()) {
            Map<String, Object> newData = new HashedMap();
            newData.put("levelCode", levelCode);
            newData.put("levelName", levelName);
            newData.put("maxCharge", maxCharge);
            newData.put("minCharge", minCharge);
            newData.put("rebate", rebate);
            newData.put("showIndex", 1);
            newData.put("agentId", agentId);
            vipgradeUtils.addVipgradeFree(newData);
        }


        DicParamUtils paramUtils = new DicParamUtils();
        Map<String, Object> navCdt = new HashedMap();
        navCdt.put("paramName", DicParamEnum.DEFAULT_USER_LEVEL.getVal());
        navCdt.put("agentId", agentId);
        DicParam dicParam = paramUtils.qryDicParams(navCdt);
        if(dicParam == null){
            Map<String, Object> navVal = new HashedMap();
            navVal.put("paramName", DicParamEnum.DEFAULT_USER_LEVEL.getVal());
            navVal.put("paramValue", levelCode);
            navVal.put("paramType", 1);
            navVal.put("agentId",agentId);
            paramUtils.newDicParam(navVal);
        }
    }
}
